package com.geeyuu.android.activity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.geeyuu.android.GeePrefrence;
import com.geeyuu.android.R;
import com.geeyuu.android.utils.AndroidUtil;

public class AppOptionsActivity extends BaseActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.TAG = "Activity4_plus";
        super.onCreate(savedInstanceState);
        setContentView(R.layout.app_options_layout);

        initTitleViews();
        initContentViews();

    }

    private void initTitleViews() {
        
        Button topLeftButton = (Button)findViewById(R.id.top_left_button);
        topLeftButton.setVisibility(View.VISIBLE);
        topLeftButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.title_back_icon, 0, R.drawable.title_icon_setup, 0);
        topLeftButton.setPadding(AndroidUtil.dip2px(this, 5), 0, 0, 0);
        ViewGroup.LayoutParams vl = topLeftButton.getLayoutParams();
        if(null == vl){
            vl = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT);
        }else{
            vl.width = ViewGroup.LayoutParams.WRAP_CONTENT;
            vl.height = ViewGroup.LayoutParams.FILL_PARENT;
        }
        topLeftButton.setLayoutParams(vl);
        topLeftButton.setOnClickListener(mOnClickListener);
        
    }

    private TextView tvReceivePushMsg;
    private TextView tvVoiceOn;

    private void initContentViews() {
        findViewById(R.id.tv_add_coins).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_edit_pwd).setOnClickListener(mOnClickListener);
        tvReceivePushMsg = (TextView) findViewById(R.id.tv_receive_push_msg);
        tvReceivePushMsg.setOnClickListener(mOnClickListener);
        if (GeePrefrence.getIsReceivePushMsg(this)) {
            tvReceivePushMsg.setCompoundDrawablesWithIntrinsicBounds(R.drawable.receive_push_msg_icon, 0,
                    R.drawable.on_icon, 0);
        } else {
            tvReceivePushMsg.setCompoundDrawablesWithIntrinsicBounds(R.drawable.receive_push_msg_icon, 0,
                    R.drawable.off_icon, 0);
        }
        findViewById(R.id.tv_unlogin).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_about).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_find_user).setOnClickListener(mOnClickListener);
        findViewById(R.id.shake_container).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_login_lock).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_black_list).setOnClickListener(mOnClickListener);
        findViewById(R.id.tv_suggestion).setOnClickListener(mOnClickListener);

        tvVoiceOn = (TextView) findViewById(R.id.tv_voice);
        tvVoiceOn.setOnClickListener(mOnClickListener);
        if (GeePrefrence.getIsVoiceOn(this)) {
            tvVoiceOn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice_icon, 0, R.drawable.on_icon, 0);
        } else {
            tvVoiceOn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice_icon, 0, R.drawable.off_icon, 0);
        }
    }

    private OnClickListener mOnClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.top_left_button:
                finish();
                break;
            case R.id.tv_add_coins:
                break;
            case R.id.tv_edit_pwd:
                break;
            case R.id.tv_receive_push_msg:
                if (GeePrefrence.getIsReceivePushMsg(AppOptionsActivity.this)) {
                    GeePrefrence.setIsReceivePushMsg(AppOptionsActivity.this, false);
                    tvReceivePushMsg.setCompoundDrawablesWithIntrinsicBounds(R.drawable.receive_push_msg_icon, 0,
                            R.drawable.off_icon, 0);
                } else {
                    GeePrefrence.setIsReceivePushMsg(AppOptionsActivity.this, true);
                    tvReceivePushMsg.setCompoundDrawablesWithIntrinsicBounds(R.drawable.receive_push_msg_icon, 0,
                            R.drawable.on_icon, 0);
                }
                break;
            case R.id.tv_unlogin:
                break;
            case R.id.tv_about:
                break;
            case R.id.tv_find_user:
                break;
            case R.id.shake_container:
                break;
            case R.id.tv_login_lock:
                break;
            case R.id.tv_black_list:
                break;
            case R.id.tv_suggestion:
                break;
            case R.id.tv_voice:
                if (GeePrefrence.getIsVoiceOn(AppOptionsActivity.this)) {
                    GeePrefrence.setIsVoiceOn(AppOptionsActivity.this, false);
                    tvVoiceOn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice_icon, 0, R.drawable.off_icon, 0);
                } else {
                    GeePrefrence.setIsVoiceOn(AppOptionsActivity.this, true);
                    tvVoiceOn.setCompoundDrawablesWithIntrinsicBounds(R.drawable.voice_icon, 0, R.drawable.on_icon, 0);
                }
                break;
            }
        }
    };

}
